﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.IO;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.DataVisualization.Charting;
using System.Data.SqlClient;
using System.Xml.Linq;
using System.Threading;
using System.Globalization;
using Nivdal.AuxCode;

namespace Nivdal
{
    public partial class ChatRoomDetails : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            OnlineUser ou = (OnlineUser)Session["User"];

            if (!HttpContext.Current.User.Identity.IsAuthenticated)
                Response.Redirect("~/Default.aspx");

            if (Request.QueryString["Id"] != null)
            {
                string ChatroomId = Request.QueryString["Id"];

                if (GND.ReadNivdalBoolData("UserId", "ChatroomId", "Nivdal_CanUserSeeChatRoom", ou.UserId, ChatroomId))
                {
                    if (!IsPostBack)
                    {
                        ChatMessagesDataSource.SelectParameters.Add("ChatroomId", ChatroomId);
                        ChatMessagesDataSource.SelectParameters.Add("UserId", ou.UserId);
                        ChatMessagesDataSource.SelectParameters.Add("MessageCount", "1000");
                        PageTitleLabel.Text = "chat room " + ChatroomId;
                    }
                }
                else
                {
                    Response.Redirect("~/TeamHomePage.aspx");
                }        

            }
            else
                Response.Redirect("~/TeamHomePage.aspx");
        }

        protected override void InitializeCulture()
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ou.UICulture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ou.Culture);
        }
    }
}